<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>发送日志事件</title>
</head>
<body>
    <h2>发送日志事件</h2>
    <form id="logForm">
        <label>日志级别(level):
            <select name="level" required>
                <option value="INFO">INFO</option>
                <option value="WARN">WARN</option>
                <option value="ERROR">ERROR</option>
                <option value="DEBUG">DEBUG</option>
            </select>
        </label><br><br>
        <label>消息(message): <input type="text" name="message" required></label><br><br>
        <label>时间戳(timestamp): <input type="text" name="timestamp" id="timestamp" required readonly></label><br><br>
        <label>线程(thread): <input type="text" name="thread"></label><br><br>
        <label>logger: <input type="text" name="logger"></label><br><br>
        <label>trace_id: <input type="text" name="trace_id"></label><br><br>
        <label>span_id: <input type="text" name="span_id"></label><br><br>
        <button type="submit">发送</button>
    </form>
    <div id="result"></div>
    <script>
        function setCurrentTimestamp() {
            document.getElementById('timestamp').value = Date.now();
        }
        setCurrentTimestamp();
        document.getElementById('logForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            setCurrentTimestamp();
            const form = e.target;
            const data = {
                level: form.level.value,
                message: form.message.value,
                timestamp: form.timestamp.value,
                thread: form.thread.value,
                logger: form.logger.value,
                trace_id: form.trace_id.value,
                span_id: form.span_id.value
            };
            document.getElementById('result').innerText = '正在发送...';
            try {
                const response = await fetch('/log/event', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(data)
                });
                const text = await response.text();
                document.getElementById('result').innerText = '返回: ' + text;
            } catch (err) {
                document.getElementById('result').innerText = '请求失败: ' + err;
            }
        });
    </script>
</body>
</html> 